<template>
  <div class="details-game public-views">
    <div class="public-inner details-wrap" id="wrap">
      <!-- 顶部导航  -->
      <pubilc-sub-nav :navList="GameSubNav"></pubilc-sub-nav>
      <!-- 左边侧边栏  -->
      <left-sidebar :data="GameDetails.sidebarGame" id="sidebar"></left-sidebar>
      <!-- 游戏详情介绍  -->
      <div class="game-content">
        <h4>游戏详情</h4>
        <div class="content-swiper">
          <div v-swiper:mySwiper="GameSwiper" style="height: 100%; padding: 40px 0">
            <div class="swiper-wrapper">
              <div class="swiper-slide" v-for="(item, index) in GameDetails.carousel">
                <img :style="imageStyle" :src="item.src" :alt="item.alt">
              </div>
            </div>
            <!-- Add Arrows -->
            <div class="swiper-button-next"></div>
            <div class="swiper-button-prev"></div>
            <div class="swiper-pagination"></div>
          </div>
        </div>
        <div class="content-details" v-html="GameDetails.content[0]"></div>
        <h4>游戏礼包</h4>
        <ul class="content-gift">
          <li v-for="(item, index) in GameDetails.gameGift">
            <h3>{{item.title}}</h3>
            <p>剩余数量
              <span>{{item.number}}</span>
              <i>/{{item.total}}</i>
            </p>
            <p>截止时间
              <span>{{item.time}}</span>
            </p>
            <a href="javascript:;">领取礼包</a>
          </li>
        </ul>
        <h4>开服时间</h4>
        <div class="content-plan">
          <div class="plan-left plan-list">
            <h3>即将开服</h3>
            <div class="list-item" v-for="(item, index) in GameDetails.gamePlan" v-if="item.isPlan">
              <div class="list-round">
                <a href="javascript:;">
                  <span>
                    <i></i>
                  </span>
                </a>
              </div>
              <h2>{{item.time}}</h2>
              <p>{{item.area}}</p>
            </div>
          </div>
          <div class="plan-right plan-list">
            <h3>已开服</h3>
            <div class="list-item" v-for="(item, index) in GameDetails.gamePlan" v-if="!item.isPlan">
              <div class="list-round">
                <a href="javascript:;">
                  <span>
                    <i></i>
                  </span>
                </a>
              </div>
              <h2>{{item.time}}</h2>
              <p>{{item.area}}</p>
            </div>
          </div>
        </div>
        <h4>游戏活动</h4>
        <ul class="content-activity">
          <li v-for="(item, index) in GameDetails.gameActivity">
            <h4>{{item.title}}</h4>
            <p class="time">{{item.time}}</p>
            <p class="content">{{item.content.substring(0, 50)}}...</p>
            <a href="javascript:;">详情
              <i class="iconfont icon-gengduo"></i>
            </a>
          </li>
        </ul>
      </div>
    </div>
    <!-- 相似游戏  -->
    <div class="public-inner">
      <div class="bottom-game">
        <h3 class="home-title">相似游戏</h3>
        <div class="bottom-swiper">
          <div v-swiper:toSwiper="bottomSwiper" v-if="bottomGame">
            <div class="swiper-wrapper">
              <div class="swiper-slide" v-for="(item, index) in bottomGame">
                <a :href="item.link">
                  <i :style="'background-image: url('+ item.icon +')'"></i>
                  <p>{{item.name}}</p>
                </a>
              </div>
            </div>
            <!-- Add Arrows -->
            <div class="swiper-button-next"></div>
            <div class="swiper-button-prev"></div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
const PubilcSubNav = () => import('@/components/PublicSubNav.vue')
const leftSidebar = () => import('@/components/leftSidebar.vue')
export default {
  components: {
    PubilcSubNav,
    leftSidebar
  },
  asyncData({ store, route }) {
    return store.dispatch('fetchGameDetails', { doAjax: 'game', gameId: route.query.gameId, cache: true })
  },
  title() {
    return `米娱游戏_${this.GameDetails.sidebarGame.name}`
  },
  computed: {
    GameDetails: function() {
      return this.$store.state.GameDetails
    },
    imageStyle: function() {
      return this.GameDetails.sidebarGame.download_number ? 'width: 600px; height: 360px' : 'width: 220px; height: 360px'
    },
    bottomGame: function() {
      return this.$store.state.bottomGame
    }
  },
  data() {
    return {
      GameSubNav: [
        { text: '游戏', href: '/game', activate: false },
        { text: '游戏详情', href: '/details/game?gameId' + this.$route.query.gameId, activate: true }
      ],
      GameSwiper: {
        loop: true,
        autoplay: true,
        navigation: {
          nextEl: '.swiper-button-next',
          prevEl: '.swiper-button-prev',
        },
        pagination: {
          el: '.swiper-pagination',
          type: 'fraction',
        }
      },
      bottomSwiper: {
        slidesPerView: 8,
        navigation: {
          nextEl: '.swiper-button-next',
          prevEl: '.swiper-button-prev',
        }
      }
    }
  },
  mounted() {
    const wrap = document.getElementById('wrap')
    const sidebar = document.getElementById('sidebar')
    window.onscroll = () => {
      const t = document.body.scrollTop || document.documentElement.scrollTop
      if (t >= sidebar.offsetTop && t <= (wrap.offsetHeight - 700)) {
        sidebar.style.transform = 'translateY(' + (t - 210) + 'px)'
      } else if (t >= (wrap.offsetHeight - 700)) {
        sidebar.style.transform = 'translateY(' + (wrap.offsetHeight - 863) + 'px)'
      } else if (t <= sidebar.offsetTop) {
        sidebar.style.transform = 'none'
      }
    }
  }
}
</script>

<style lang="less" scoped>
.details-wrap {
  margin-bottom: 40px;
}

.game-content {
  width: 880px;
  padding: 30px;
  float: right;
  box-shadow: 1px 1px 10px 1px #eee;
  background: #fff;
  &>h4 {
    color: #333;
    line-height: 42px;
    background: #eee;
    text-align: center;
  }
  .content-swiper {
    text-align: center;
    img {
      max-width: 100%;
      vertical-align: middle;
    }
  }
  .content-details {
    line-height: 28px;
    text-indent: 2em;
    color: #999;
    font-size: 14px;
    padding: 10px 25px 50px;
  }
  .content-gift {
    padding: 30px 0 50px;
    overflow: hidden;
    li {
      width: 278px;
      height: 150px;
      border: 1px solid #2cd0ff;
      color: #2cd0ff;
      margin-right: 20px;
      margin-bottom: 20px;
      float: left;
      position: relative;
      h3 {
        line-height: 52px;
        padding-left: 20px;
      }
      p {
        padding-left: 20px;
        margin-bottom: 10px;
        color: #999;
        span {
          margin-left: 10px;
          color: #2cd0ff
        }
      }
      a {
        position: absolute;
        left: 0;
        bottom: 0;
        width: 100%;
        line-height: 44px;
        text-align: center;
        font-size: 18px;
        font-weight: bold;
        color: #fff;
        background-color: #2cd0ff;
        &:before {
          content: '';
          width: 100%;
          height: 8px;
          background-image: url('../../assets/icon/details_game_icon_01.png');
          background-repeat: no-repeat;
          background-size: 100% 100%;
          position: absolute;
          left: 0;
          top: -4px;
        }
      }
      &:nth-child(3n+2) {
        border: 1px solid #ffa93a;
        color: #ffa93a;
        p {
          padding-left: 20px;
          margin-bottom: 10px;
          color: #999;
          span {
            margin-left: 10px;
            color: #ffa93a
          }
        }
        a {
          background-color: #ffa93a;
          &:before {
            background-image: url('../../assets/icon/details_game_icon_02.png');
            background-size: 100% 100%;
          }
        }
      }
      &:nth-child(3n+3) {
        margin-right: 0;
        border: 1px solid #88d42f;
        color: #88d42f;
        p {
          padding-left: 20px;
          margin-bottom: 10px;
          color: #999;
          span {
            margin-left: 10px;
            color: #88d42f
          }
        }
        a {
          background-color: #88d42f;
          &:before {
            background-image: url('../../assets/icon/details_game_icon_03.png');
            background-size: 100% 100%;
          }
        }
      }
    }
  }
  .content-activity {
    padding: 30px 0;
    overflow: hidden;
    li {
      width: 388px;
      border: 1px solid #ffbb64;
      height: 174px;
      padding: 0 20px;
      float: left;
      margin-right: 18px;
      margin-bottom: 20px;
      position: relative;
      &:nth-child(2n) {
        margin-right: 0;
      }
      h4 {
        line-height: 54px;
        color: #333;
      }
      p {
        line-height: 26px;
        font-size: 14px;
      }
      .time {
        color: #ffbb64;
        margin-bottom: 15px;
      }
      .content {
        height: 52px;
        overflow: hidden;
      }
      a {
        position: absolute;
        width: 80px;
        line-height: 32px;
        right: 0;
        bottom: 5px;
        text-align: center;
        color: #2cd0ff;
        font-size: 14px;
      }
      i {
        vertical-align: top;
        font-size: 14px;
      }
    }
  }
  .content-plan {
    padding: 40px 0 60px;
    overflow: hidden;
    .plan-list {
      width: 366px;
      padding-left: 72px;
      float: left;
      h3 {
        line-height: 46px;
        font-weight: 700;
      }
    }
    .list-item {
      border-left: 2px solid #eee;
      padding: 30px 0;
      position: relative;
      width: 248px;
      h2 {
        height: 30px;
        line-height: 30px;
        background-color: #ffbb64;
        color: #fff;
        text-align: center;
        font-size: 16px;
        border-radius: 15px;
        margin-bottom: 25px;
      }
      p {
        line-height: 40px;
        padding-left: 24px;
        color: #666;
        font-size: 16px;
      }
    }
    .list-round {
      width: 50px;
      height: 50px;
      border-radius: 50%;
      background-color: #fff;
      position: absolute;
      left: -25px;
      top: 20px;
      z-index: 2;
      a {
        width: 24px;
        height: 24px;
        border-radius: 50%;
        background: #ffcf92;
        position: absolute;
        left: 50%;
        top: 50%;
        margin: -12px 0 0 -12px;
      }
      span {
        width: 14px;
        height: 14px;
        border-radius: 50%;
        background: #fff;
        position: absolute;
        left: 50%;
        top: 50%;
        margin: -7px 0 0 -7px;
      }
      i {
        width: 8px;
        height: 8px;
        border-radius: 50%;
        background: #ffa93a;
        position: absolute;
        left: 50%;
        top: 50%;
        margin: -4px 0 0 -4px;
      }
    }
    .plan-right {
      .list-item {
        h2 {
          background-color: #ccc;
        }
        p {
          color: #ccc;
        }
      }
      .list-round {
        a {
          background: #e5e5e5;
        }
        i {
          background: #ccc;
        }
      }
    }
  }
}

.bottom-game {
  height: 200px;
  background: #fff;
  padding: 10px 20px 30px;
  .bottom-swiper {
    padding: 20px 0;
    a {
      display: block;
      text-align: center;
    }
    i {
      display: block;
      width: 88px;
      height: 88px;
      margin: 0 auto;
      background-size: 100%;
    }
    p {
      text-align: center;
      padding-top: 20px;
      font-weight: 600;
      white-space: nowrap;
      text-overflow: ellipsis;
      overflow: hidden;
      text-align: center;
      font-size: 16px;
    }
  }
}
</style>

